using System.Collections.Generic;
using UnityEngine;

namespace Gj
{
    public static class TerrainCategoryTools
    {
        private static readonly string[] list;

        static TerrainCategoryTools()
        {
            var settings = LoadSettings();
            list = settings.categorys;
        }

        private static TerrainCategorySettings LoadSettings()
        {
            var loadedSettings = (TerrainCategorySettings)Resources.Load("TerrainCategorySettings", typeof(TerrainCategorySettings));
            if (loadedSettings == null)
            {
                loadedSettings = ScriptableObject.CreateInstance<TerrainCategorySettings>();
                Debug.LogError("TerrainCategorySettings is not exist (Resources)");
            }

            return loadedSettings;
        }

        public static int Get(string key)
        {
            if (key == "") return -1;
            for (int i = 0; i < list.Length; i++)
            {
                if (key == list[i]) return i;
            }
            return -1;
        }

        public static string Get(int index)
        {
            if (index == -1) return "";
            return list[index];
        }
    }
}